package com.ktjy.service;

import com.ktjy.entity.Page;
import com.ktjy.entity.UserAco;
import com.ktjy.entity.Book;
import com.ktjy.mapper.Bookmapper;
import com.ktjy.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("bookService")
public class BookServiceImpl implements BookService {
    @Autowired
    private Bookmapper bookmapper;

    public void setBookmapper(Bookmapper bookmapper) {
        this.bookmapper = bookmapper;
    }

    @Override
    public List<Book> bookList() {
        return bookmapper.getBooks();
    }

    @Override
    public int insert(Book book) {
        return bookmapper.addBook(book);
    }

    @Override
    public int delete(Book book) {
        return bookmapper.deleteBook(book);
    }

    @Override
    public Book selectByIdBook(Book book) {
        return bookmapper.selectByIdBook(book);
    }

    @Override
    public int updateByIdBook(Book book) {
        return bookmapper.updateBook(book);
    }

    @Override
    public UserAco selectAccount(UserAco userAco){
        return bookmapper.selectAccount(userAco);
    }

    @Override
    public Page findPageVo(Book book, Integer pageNo, Integer pageSize) {
        Page page=new Page();
        //查询总记录数
        Integer count=bookmapper.count(book);
        page.setRows(pageSize);
        page.setTotal(count);
        page.setTotalPage(pageNo);
        //查询信息
        List<Book> list=bookmapper.pageBooks(book,page.offset(),page.getRows());
        page.setList(list);
        return page;
    }

}
